// JavaScript Document
var requestUrl="/euc/";
var space_id=getQueryString("space_id");
var pic=getQueryString("pic");
var space_name=getQueryString("space_name");
$(function(){
/* 	
	$.ajax({
		type: "get",
		url: requestUrl+'_space/space_list',
		dataType:'json',
		//data:{  "space_id": 1, "contact": uname,"contact_number":utel, "visit_time":visit_time},
		success: function(data) {
			var str='';
			$.each(data.data.list,function(index,value){
				str+='<div class="spaceMore"> <div class="group"><div class="picCon"><img src="'+requestUrl+value.displayPicture+'"></div><h3>'+value.spaceName+'</h3><p>'+value.address+'</p><a href="'+requestUrl+value.detailUrl+'" class="view">查看</a></div></div>'; 
			});
			$(".cityGroup").html(str);
		}
	});
	
	 */
	//提交申请

	$(".submit").on("click",function(){
	var uname = $("#name").val();
    var utel = $("#tel").val();
   	var visit_time = $("#visit_time").val();
    var d = new Date();
    var y = d.getFullYear(); // 2018
    var m = d.getMonth() + 1; // 3
    var da = d.getDate(); // 17
    var date_str = y + '-' + m + '-' + da;
	    if(uname==""||uname=="姓名"){
	        alert("请输入姓名");
	        $("#uname").focus();           
	        return false;
	    }else if(utel==""||utel=="手机" || !validMobile(utel)){
	        alert("请输入电话号码");
	        $("#utel").focus();           
	        return false;
	    }else if(!visit_time){
			alert("请选择参观日期");
	        return false;
		}else{
			$.ajax({
				type: "get",
				url: requestUrl+'_space/space_reserve',
				dataType:'json',
				data:{  "space_id":space_id, "contact": uname,"contact_number":utel, "visit_time":visit_time, "source_channe":"wx"},
				success: function(data) {
					if(data.status==0){
						$(".success p span").html(visit_time);

				    	if(visit_time < date_str){
				    		alert("请选择今天及以后的时间")
				    	}else{
							$('.success').show();	
						}

					}else{
						alert(data.message);
					}
				}
			});
		}
    })



	//关闭弹窗
	$(".okBtn").on("click",function(){
        $(".page1,.success").hide();
        $(".page2").show();

		var ename = $("#name").val();
	    var etel = $("#tel").val();
	   	var etime = $("#timer").text();

	   	$(".success1").html(ename)
	   	//$(".success2").html(etel)
	   	$(".success3").html(etime)
    })

	//城市切换
    $(".tab li").on("click",function(){
        $(this).addClass("cur").siblings().removeClass("cur");
        $(".cityGroup").eq($(".tab li").index(this)).addClass("on").siblings().removeClass("on");
    })

	
    
});

function validMobile(mobile){	
	var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(14[0-9]{1})|(17[0-9]{1}))+\d{8})$/; 
	if(!mobile || !reg.test(mobile) ){	
		return false;
	}else{
		return true;
	}
}

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    var q = window.location.pathname.substr(1).match(reg_rewrite);
    if(r != null){
        return unescape(r[2]);
    }else if(q != null){
        return unescape(q[2]);
    }else{
        return null;
    }
}